using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(PolygonCollider2D))]
public class HitHurt : MonoBehaviour
{
    [SerializeField] private int hitDamage;
    [SerializeField] private float damageInterval;
    [SerializeField] private float damageTimer;
    private void Awake()
    {
        GetComponent<PolygonCollider2D>().isTrigger = true;
    }

   
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            PlayerAttribute.Instance.PlayerGetHurt(hitDamage);
        }
    }

    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            if (damageTimer < damageInterval)
            {
                damageTimer += Time.deltaTime;
            }
            else
            {
                PlayerAttribute.Instance.PlayerGetHurt(hitDamage);
                damageTimer = 0;
            }
        }
    }
}
